package cn.cvs.service.impl;

import cn.cvs.dao.SysUserMapper;
import cn.cvs.pojo.SysUser;
import cn.cvs.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
@Service("sysUserService")
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    private SysUserMapper sysUserMapper;


    @Override
    public List<SysUser> getList(SysUser sysUser) {
        try {
            return sysUserMapper.selectSysUserList(sysUser);
        }catch (RuntimeException e){
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public int deleteId(int id) {
        return sysUserMapper.deleteId(id);
    }

    @Override
    public boolean add(SysUser sysUser) {
        boolean result = false;
        try {
            if (true == sysUserMapper.add(sysUser)) {
                result = true;
                //测试事务回滚时，打开注释
//                throw new RuntimeException();
            }
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
        return result;
    }

    @Override
    public int update(SysUser sysUser) {
        return sysUserMapper.update(sysUser);
    }


    public void setSysUserMapper(SysUserMapper sysUserMapper) {
        this.sysUserMapper = sysUserMapper;
    }
}
